package main

import (
	"fmt"
	"github.com/gogap/logs"
	"yundian/internel/app/dao"
	"yundian/internel/app/logic"
	"yundian/internel/app/models/devices"
	"yundian/internel/app/models/orders"
	"yundian/internel/pkg/dbs"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)

func main() {
	//dingo.InitViper("./configs/adm.yaml")
	//dingo.InitViper("./configs/yundian.yaml")
	dingo.InitViper("./configs/zhongman.yaml")
	//dingo.InitViper("./configs/zmtest.yaml")
	//dingo.InitViper("./configs/zmtest-adm.yaml")
	dbs.NewMysqlComponent().Step()
	dbs.NewRedisComponent().Step()

	orderList := make([]*orders.OrderModel, 0)

	// AND FROM_UNIXTIME(end_at)>'2021-07-10'
	sql := `SELECT * FROM orders WHERE trade_no NOT IN (SELECT trade_no FROM dividends_log) AND state=5 AND 
	settlement_money>1 AND user_id>0 AND place_id>0`

	if db := global.Orm.Debug().Raw(sql).Find(&orderList); db.Error != nil {
		logs.Error(db.Error)
	}

	for _, item := range orderList {
		fmt.Println(item)
		devInfo := dao.NewDeviceDao().FetchDeviceInfoWithType(item.DeviceSn).Unwrap().(*devices.DeviceType)
		logic.NewOrderLogic().CalOrderDividends(item, devInfo, item.SettlementMoney, int64(item.EndAt))
	}
}
